package com.mediacloud.app.newsmodule.fragment.ugc.publish

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.fragment.ugc.mod.CmsCatalog


class LiteCmsCatalogListAdapter(val context: Context, val call: ICatalogListener) : RecyclerView.Adapter<LiteCmsCatalogListAdapter.CmsCatalogHolder>() {
    val data: MutableList<CmsCatalog> = ArrayList()
    fun setData(data: MutableList<CmsCatalog>?) {
        this.data.clear()
        data?.let {
            this.data.addAll(it)
        }
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CmsCatalogHolder {
        return CmsCatalogHolder(LayoutInflater.from(context).inflate(R.layout.item_lite_av_catalog_item, parent, false))
    }

    override fun onBindViewHolder(holder: CmsCatalogHolder, position: Int) {
        holder.hotTitle.text = data[position].name
        if (position == 0) {
            holder.catalogTag.visibility = View.GONE
        } else {
            holder.catalogTag.visibility = View.VISIBLE
        }
        holder.itemView.setOnClickListener {
            call.onCatalog(position,data[position])
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }

    class CmsCatalogHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val hotTitle: TextView = itemView.findViewById(R.id.hotTitle)
        val catalogTag: TextView = itemView.findViewById(R.id.catalogTag)
    }
}